home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3984 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  49 lines

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How do I combin C and C++ code into a simple VC++ project?
  5. Date: 26 Jan 1996 22:32:39 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4ebkq7$j44@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe12.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 26, 1996 17:00:02 in article <How do I combin C and C++ code into a
  15. simple VC++ project?>, 'howard@vvm.com (Jon Howard)' wrote: 
  16.  
  17.  
  18. >I have a project where the majority of the code is C, but I want to 
  19. >call some functions written in C++ (that are sitting in a different 
  20. >file). They all compile great, but at link time the compiler can't 
  21. >seem to find the C++ function. Is this type of mixing not allowed? I'm 
  22. >using Visual C++ 1.5 on Win 3.1. 
  23. Yes.  Read about extern "C" declaration.  Example: 
  24.  
  25. File cppfuncs.h (which is the header file include in both C and C++ 
  26. source modules): 
  27.  
  28. #if defined(__cplusplus) 
  29. extern "C" { 
  30. #endif 
  31.  
  32. int CppFunc(int foo, char * bar); 
  33. [more C++ function declarations] 
  34.  
  35. #if defined(__cplusplus) 
  36.  } 
  37. #endif 
  38.  
  39. BTW, do not attempt to export class member functions this 
  40. way -- well, I suppose you could export static members, but 
  41. that's beyod the scope of this msg. 
  42.  
  43. Another BTW:  Note that __cplusplus has two underscores. 
  44. -- 
  45. Pete Grant 
  46. Kalevi, Inc. 
  47. Object Oriented Software Development
  48.